package singleton;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 08 - 27
 * Time:10:59
 */

/***
 * 题目：设计一个类，该类只能生成一个实例
 * 解法3——synchronized方法可以同步所有的线程，让线程变成串行一个一个去new，同样会出现很多实例，——将判断（instance == null）也同步起来
 */
public class Singleton3 {

    private static Singleton3 instance = null;

    private Singleton3(){

    }

    public static Singleton3 getInstance(){
        synchronized (Singleton3.class){
            if(instance == null){
                instance = new Singleton3();
            }
        }
        return  instance;
    }
}
